package com.yunxin.core.domain.model.order;

import cn.hutool.core.date.DateTime;
import com.yunxin.core.application.admin.team.DistributeDo;
import com.yunxin.core.application.command.order.OperateAllocationOrderRest;
import com.yunxin.core.utils.infra.support.request.PushOrderDTO;

import java.util.Date;
import java.util.List;

/**
 * @author zero°
 * @since 2023-07-12
 */
public interface OrderUserApplyAllocationRepository {

    /**
     * 保存
     * @param orderUserApplyAllocation orderUserApplyAllocation
     * @return boolean
     */
    boolean saveOrderUserApplyAllocation(OrderUserApplyAllocation orderUserApplyAllocation);

    /**
     * 更新
     * @param orderUserApplyAllocation orderUserApplyAllocation
     * @return int
     */
    int updateOrderUserApplyAllocation(OrderUserApplyAllocation orderUserApplyAllocation);

    /**
     * 更新分配单微信号
     * @param id id
     * @param wechat wechat
     * @return boolean
     */
    boolean updateAllocationOrderWechatById(Long id, String wechat);

    /**
     * 更新分配单企业微信
     * @param id id
     * @param enterpriseWechat enterpriseWechat
     * @return boolean
     */
    boolean updateAllocationOrderEnterpriseWechatById(Long id, String enterpriseWechat);

    /**
     * 根据id查询
     * @param id id
     * @return OrderUserApplyAllocation
     */
    OrderUserApplyAllocation getOrderUserApplyAllocationById(Long id);

    /**
     * 根据产品id获取时间内分配订单条数
     * @param productId productId
     * @param productStartTime productStartTime
     * @param productEndTime productEndTime
     * @return int
     */
    int getAllocationOrderCountByProductId(Long productId, Date productStartTime, Date productEndTime);

    /**
     * 根据申请订单id及分配单分配类型查询数据
     * @param applyOrderNo applyOrderNo
     * @param allocationTypes allocationTypes
     * @return OrderUserApplyAllocation
     */
    OrderUserApplyAllocation getByApplyOrderNoAndAllocationTypes(String applyOrderNo, List<Integer> allocationTypes);

    /**
     * 根据商户id查询用户时间内最早的分配单id
     * @param userCode userCode
     * @param merchantId merchantId
     * @param startTime startTime
     * @param endTime endTime
     * @return Long
     */
    Long getAllocationIdByUserAndMerchant(String userCode, Long merchantId, Date startTime, Date endTime);

    /**
     * 根据商户id查询最后一笔分配单账户id
     * @param merchantId merchantId
     * @return Long
     */
    Long getAllocationOrderLastAccountIdByMerchant(Long merchantId,String code);

    /**
     * 查询当前商户信息
     * @param userId
     * @return
     */
    Long merchantIdByUserId(Long userId);

    int saveTeamTask(DistributeDo distributeDo);

    List<DistributeDo> selectTeamTask(DateTime startTime,DateTime endTime);

    /**
     * 根据订单查询订单详情
     * @param orderIds
     * @return
     */
    List<OrderUserApplyAllocation> selectOrderDetail(List<Long> orderIds);

    /**
     * 校验订单是否被分配
     * @param orderIds
     * @return
     */
    List<Integer> selectalreadyDistribute(List<Long> orderIds);

    /**
     * 根据订单号查询用户详情
     * @param customerId
     * @return
     */
    PushOrderDTO selectOrderDetailByApplyOrderNo(Integer customerId);



    /**
     * 根据产品id获取时间内分配订单条数
     * @param merchantId merchantId
     * @param productStartTime productStartTime
     * @param productEndTime productEndTime
     * @return int
     */
    Integer getAllocationOrderCountByMerchantId(Long merchantId, Date productStartTime, Date productEndTime);

}
